<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getUrlParam(sUrl, sKey) {
        let url = sUrl.split("?")[1].split("#")[0].split('&');
        
       url =  url.reduce((pre,cur)=> {
           cur =  cur.split("=")
            if(cur[0] == sKey) return [...pre,cur[1]]
                return pre
        },[])
        console.log(url);
        if(url[1]) {
            return url
        } else {
            url[0]
        }
    //   return  url.length == 1 ? url[0] : url
      }
      getUrlParam("http://www.nowcoder.com?key=1&key=2&key=3&test1=4#hehe","test1")
    </script>
  </body>
</html>
